# coding: UTF-8
# ----------
# Project_Name : pythonProject
# File_Name : huangcongbing
# Author : asus
# Date_Time:2022/4/22 9:53
# Description :
# ----------
from selenium import  webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
def foo1():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get(r"D:\pyworkspace\T79\pythonProject\selenium3\example.html")
    time.sleep(3)
    #找到下拉菜单元素<select>
    el = driver.find_element(By.ID,'Selector')
    #构造下拉菜单的对象
    select = Select(el)

    #根据选项option的value属性选择
    select.select_by_value('peach')
    time.sleep(3)

    #根据option的text选择
    select.select_by_visible_text('3.香蕉')
    time.sleep(3)

    #根据option索引值选择:从0开始
    select.select_by_index(4)
    time.sleep(2)

    driver.quit()

if __name__=="__main__":
    foo1()